<template>
  <div class="auditor-dashboard">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1>审核概览</h1>
      <p>欢迎回来，{{ authStore.userInfo?.name }}！这里是您的审核工作台</p>
    </div>

    <!-- 统计卡片 -->
    <a-row :gutter="16" class="stats-row">
      <a-col :span="6">
        <a-card class="stat-card pending">
          <div class="stat-content">
            <div class="stat-icon">
              <ClockCircleOutlined />
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ statistics.pending }}</div>
              <div class="stat-label">待审核</div>
            </div>
          </div>
        </a-card>
      </a-col>
      <a-col :span="6">
        <a-card class="stat-card today">
          <div class="stat-content">
            <div class="stat-icon">
              <CheckCircleOutlined />
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ statistics.today }}</div>
              <div class="stat-label">今日已审</div>
            </div>
          </div>
        </a-card>
      </a-col>
      <a-col :span="6">
        <a-card class="stat-card week">
          <div class="stat-content">
            <div class="stat-icon">
              <BarChartOutlined />
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ statistics.week }}</div>
              <div class="stat-label">本周已审</div>
            </div>
          </div>
        </a-card>
      </a-col>
      <a-col :span="6">
        <a-card class="stat-card efficiency">
          <div class="stat-content">
            <div class="stat-icon">
              <RocketOutlined />
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ statistics.efficiency }}%</div>
              <div class="stat-label">审核效率</div>
            </div>
          </div>
        </a-card>
      </a-col>
    </a-row>

    <!-- 主要内容区 -->
    <a-row :gutter="16" class="main-content">
      <!-- 左侧：待审核列表 -->
      <a-col :span="16">
        <a-card title="待审核内容" class="pending-content">
          <a-tabs v-model:activeKey="activeTab">
            <a-tab-pane key="content" tab="视频/课程">
              <div class="content-list">
                <div v-for="item in pendingContent" :key="item.id" class="content-item">
                  <div class="content-preview">
                    <img :src="item.thumbnail" :alt="item.title" />
                    <div class="content-duration">{{ item.duration }}</div>
                  </div>
                  <div class="content-info">
                    <h4>{{ item.title }}</h4>
                    <p>{{ item.description }}</p>
                    <div class="content-meta">
                      <span>上传者：{{ item.uploader }}</span>
                      <span>上传时间：{{ item.uploadTime }}</span>
                    </div>
                  </div>
                  <div class="content-actions">
                    <a-button type="primary" size="small" @click="approveContent(item.id)">
                      通过
                    </a-button>
                    <a-button size="small" @click="rejectContent(item.id)">
                      拒绝
                    </a-button>
                    <a-button size="small" @click="markViolation(item.id)">
                      违规标记
                    </a-button>
                  </div>
                </div>
              </div>
            </a-tab-pane>
            <a-tab-pane key="comments" tab="评论/弹幕">
              <div class="comment-list">
                <div v-for="comment in pendingComments" :key="comment.id" class="comment-item">
                  <div class="comment-avatar">
                    <a-avatar :src="comment.avatar" />
                  </div>
                  <div class="comment-content">
                    <div class="comment-header">
                      <span class="comment-author">{{ comment.author }}</span>
                      <span class="comment-time">{{ comment.time }}</span>
                    </div>
                    <div class="comment-text">{{ comment.content }}</div>
                    <div class="comment-context">
                      来自：{{ comment.source }}
                    </div>
                  </div>
                  <div class="comment-actions">
                    <a-button type="primary" size="small" @click="approveComment(comment.id)">
                      通过
                    </a-button>
                    <a-button size="small" @click="rejectComment(comment.id)">
                      拒绝
                    </a-button>
                    <a-button size="small" @click="markSensitive(comment.id)">
                      敏感标记
                    </a-button>
                  </div>
                </div>
              </div>
            </a-tab-pane>
            <a-tab-pane key="merchants" tab="商户申请">
              <div class="merchant-list">
                <div v-for="merchant in pendingMerchants" :key="merchant.id" class="merchant-item">
                  <div class="merchant-avatar">
                    <a-avatar :src="merchant.avatar" />
                  </div>
                  <div class="merchant-info">
                    <h4>{{ merchant.name }}</h4>
                    <p>{{ merchant.description }}</p>
                    <div class="merchant-meta">
                      <span>申请时间：{{ merchant.applyTime }}</span>
                      <span>机构：{{ merchant.institution }}</span>
                    </div>
                  </div>
                  <div class="merchant-actions">
                    <a-button type="primary" size="small" @click="approveMerchant(merchant.id)">
                      通过
                    </a-button>
                    <a-button size="small" @click="rejectMerchant(merchant.id)">
                      拒绝
                    </a-button>
                    <a-button size="small" @click="requestMoreInfo(merchant.id)">
                      要求补充
                    </a-button>
                  </div>
                </div>
              </div>
            </a-tab-pane>
          </a-tabs>
        </a-card>
      </a-col>

      <!-- 右侧：快捷操作和统计 -->
      <a-col :span="8">
        <!-- 快捷操作 -->
        <a-card title="快捷操作" class="quick-actions">
          <div class="action-buttons">
            <a-button type="primary" block @click="batchApprove">
              批量通过
            </a-button>
            <a-button block @click="batchReject">
              批量拒绝
            </a-button>
            <a-button block @click="exportReport">
              导出报告
            </a-button>
            <a-button block @click="openSettings">
              审核设置
            </a-button>
          </div>
        </a-card>

        <!-- 审核统计 -->
        <a-card title="审核统计" class="audit-stats">
          <div class="stat-chart">
            <div class="chart-item">
              <span class="chart-label">通过率</span>
              <a-progress :percent="85" status="success" />
            </div>
            <div class="chart-item">
              <span class="chart-label">拒绝率</span>
              <a-progress :percent="12" status="exception" />
            </div>
            <div class="chart-item">
              <span class="chart-label">违规率</span>
              <a-progress :percent="3" status="active" />
            </div>
          </div>
        </a-card>

        <!-- 最近活动 -->
        <a-card title="最近活动" class="recent-activity">
          <div class="activity-list">
            <div v-for="activity in recentActivities" :key="activity.id" class="activity-item">
              <div class="activity-icon">
                <CheckCircleOutlined v-if="activity.type === 'approve'" style="color: #52c41a" />
                <CloseCircleOutlined v-else-if="activity.type === 'reject'" style="color: #ff4d4f" />
                <ExclamationCircleOutlined v-else style="color: #faad14" />
              </div>
              <div class="activity-content">
                <div class="activity-text">{{ activity.text }}</div>
                <div class="activity-time">{{ activity.time }}</div>
              </div>
            </div>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useAuthStore } from '@/stores/authStore'
import { message } from 'ant-design-vue'
import {
  ClockCircleOutlined,
  CheckCircleOutlined,
  BarChartOutlined,
  RocketOutlined,
  ExclamationCircleOutlined,
  CloseCircleOutlined
} from '@ant-design/icons-vue'

const authStore = useAuthStore()
const activeTab = ref('content')

// 统计数据
const statistics = ref({
  pending: 15,
  today: 28,
  week: 156,
  efficiency: 92
})

// 待审核内容
const pendingContent = ref([
  {
    id: 1,
    title: 'Java基础入门课程',
    description: '适合初学者的Java编程基础课程',
    thumbnail: 'https://via.placeholder.com/120x80',
    duration: '45:30',
    uploader: '张老师',
    uploadTime: '2024-01-15 14:30'
  },
  {
    id: 2,
    title: 'Python数据分析实战',
    description: '使用Python进行数据分析和可视化',
    thumbnail: 'https://via.placeholder.com/120x80',
    duration: '1:20:15',
    uploader: '李老师',
    uploadTime: '2024-01-15 13:45'
  }
])

// 待审核评论
const pendingComments = ref([
  {
    id: 1,
    author: '学员小王',
    content: '这个课程讲解得很清楚，收获很大！',
    time: '2024-01-15 15:20',
    avatar: 'https://via.placeholder.com/32x32',
    source: 'Java基础入门课程'
  },
  {
    id: 2,
    author: '学员小李',
    content: '希望能有更多实战案例',
    time: '2024-01-15 15:15',
    avatar: 'https://via.placeholder.com/32x32',
    source: 'Python数据分析实战'
  }
])

// 待审核商户
const pendingMerchants = ref([
  {
    id: 1,
    name: '未来科技教育',
    description: '专注于人工智能和机器学习课程',
    applyTime: '2024-01-15 10:30',
    avatar: 'https://via.placeholder.com/32x32',
    institution: '智教易购学院'
  }
])

// 最近活动
const recentActivities = ref([
  {
    id: 1,
    type: 'approve',
    text: '通过了"Java基础入门课程"',
    time: '2分钟前'
  },
  {
    id: 2,
    type: 'reject',
    text: '拒绝了"不合适的评论内容"',
    time: '5分钟前'
  },
  {
    id: 3,
    type: 'violation',
    text: '标记了违规内容',
    time: '10分钟前'
  }
])

// 内容审核操作
const approveContent = (id: number) => {
  message.success(`已通过内容 ID: ${id}`)
  // 这里应该调用API
}

const rejectContent = (id: number) => {
  message.warning(`已拒绝内容 ID: ${id}`)
  // 这里应该调用API
}

const markViolation = (id: number) => {
  message.error(`已标记违规内容 ID: ${id}`)
  // 这里应该调用API
}

// 评论审核操作
const approveComment = (id: number) => {
  message.success(`已通过评论 ID: ${id}`)
}

const rejectComment = (id: number) => {
  message.warning(`已拒绝评论 ID: ${id}`)
}

const markSensitive = (id: number) => {
  message.error(`已标记敏感评论 ID: ${id}`)
}

// 商户审核操作
const approveMerchant = (id: number) => {
  message.success(`已通过商户申请 ID: ${id}`)
}

const rejectMerchant = (id: number) => {
  message.warning(`已拒绝商户申请 ID: ${id}`)
}

const requestMoreInfo = (id: number) => {
  message.info(`已要求商户 ID: ${id} 补充信息`)
}

// 批量操作
const batchApprove = () => {
  message.success('批量通过操作已执行')
}

const batchReject = () => {
  message.warning('批量拒绝操作已执行')
}

const exportReport = () => {
  message.info('报告导出功能开发中...')
}

const openSettings = () => {
  message.info('审核设置功能开发中...')
}

onMounted(() => {
  // 初始化数据
  console.log('审核端仪表板已加载')
})
</script>

<style scoped>
.auditor-dashboard {
  padding: 0;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  color: #333;
}

.page-header p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.stats-row {
  margin-bottom: 24px;
}

.stat-card {
  border-radius: 8px;
  overflow: hidden;
}

.stat-card.pending {
  border-left: 4px solid #1890ff;
}

.stat-card.today {
  border-left: 4px solid #52c41a;
}

.stat-card.week {
  border-left: 4px solid #722ed1;
}

.stat-card.efficiency {
  border-left: 4px solid #fa8c16;
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  font-size: 32px;
  color: #1890ff;
}

.stat-info {
  flex: 1;
}

.stat-number {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-top: 4px;
}

.main-content {
  margin-bottom: 24px;
}

.pending-content {
  min-height: 600px;
}

.content-list, .comment-list, .merchant-list {
  max-height: 500px;
  overflow-y: auto;
}

.content-item, .comment-item, .merchant-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid #f0f0f0;
}

.content-item:last-child, .comment-item:last-child, .merchant-item:last-child {
  border-bottom: none;
}

.content-preview {
  position: relative;
  flex-shrink: 0;
}

.content-preview img {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
}

.content-duration {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 6px;
  border-radius: 2px;
  font-size: 12px;
}

.content-info, .comment-content, .merchant-info {
  flex: 1;
}

.content-info h4, .merchant-info h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 500;
}

.content-info p, .comment-text, .merchant-info p {
  margin: 0 0 8px 0;
  color: #666;
  font-size: 14px;
}

.content-meta, .comment-header, .merchant-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #999;
}

.comment-author {
  font-weight: 500;
  color: #333;
}

.comment-context {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

.content-actions, .comment-actions, .merchant-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.quick-actions {
  margin-bottom: 16px;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.audit-stats {
  margin-bottom: 16px;
}

.stat-chart {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-label {
  font-size: 14px;
  color: #666;
}

.recent-activity {
  margin-bottom: 16px;
}

.activity-list {
  max-height: 300px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.activity-content {
  flex: 1;
}

.activity-text {
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
}

.activity-time {
  font-size: 12px;
  color: #999;
}

:deep(.ant-tabs-tab) {
  padding: 8px 16px;
}

:deep(.ant-card-head-title) {
  font-weight: 600;
}

:deep(.ant-progress-text) {
  font-size: 12px;
}
</style>
